﻿@{
    ViewBag.Title = "ChangeQuestionView";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}




<!--begin grid code-->


<section id="widget-grid" class="">
    <div class="row">
         <!--Operation-->
        <div class="heading-buttons">
            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class=" fa fa-file-text "></i>
                    试题库
                </h1>
            </div>
            <div class="buttons pull-right">
                <button type="button" class="btn btn-success btn-labeled "  data-bind="click:ConfirmToChange">
                   
                    <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>确认修改</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click:BackToPreview">
                    <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>取消修改</button>
            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->
        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>


                <div>
                    <label>标题：</label><div class='input-append'>
                        <input id='txtbSrSTitle' name='txtbSrSTitle' type='text' placeholder='标题' class='input-mini' style='width: 120px;' /></div>
                </div>
                <div>
                    <label>对应大纲位置：</label>
                    <select name="txtbSrSCharpter" id="txtbSrSCharpter" data-bind="event: { change: $root.myChange }">

                        <option value="">---请选择章---</option>
                        @foreach (var itemSel in ViewBag.Charpter)
                        {
                            <option value="@itemSel.SCaptailName" data-value="@itemSel.Id" >
                                @itemSel.SCaptailName</option> 
                        }

                    </select>
                    <select id="txtbSrITeaCatalog" name="txtbSrITeaCatalog" data-bind="options: arrayBindSesson,
                       optionsValue:'Id',
                       optionsText: 'SCaptailName',
                       optionsCaption: '---请选择节---'">
                    </select>
                </div>
                <div><input type="hidden"  id="txtbSrIProblemType" name="txtbSrIProblemType" value="@ViewBag.IProblemType"/></div>
                <div><input type="hidden"  id="txtbSrICousreID" name="txtbSrICousreID" value="@ViewBag.CourseID"/></div>
                <div class="clearfix">
                </div>

            </form>
        </div>
        <!--/search-->
        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>试题列表</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="radio" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="left ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                
                                              
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="radio" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>


                                                <td class='left'><strong data-bind='text: STitle'></strong></td>
                                                <td class='left'><strong data-bind='text: SCharpter'></strong></td>

                                                <td class='left'><strong data-bind='text: IHardLevel'></strong></td>


                                                
                                            
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>



                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->


                        </div>

                        <!-- /分页 -->




                    </div>
                </div>

            </div>




        </article>

    </div>
    <!--end row-->
</section>
<input id="HiddenCourseID" type="hidden" value="@ViewBag.CourseID">
<input id="HiddenPaperDetailId" type="hidden" value="@ViewBag.PaperDetailId">
<input id="HiddenIStrategyID" type="hidden" value="@ViewBag.IStrategyID">

<input id="HiddenPaperID"  type="hidden" value="@ViewBag.PaperID"/>
<script type="text/javascript">

    var gdViewModel;
    $(function () {
        $._messengerDefaults = {//IStrategyID
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            


            dialogId: "previewMessageModal", //添加对话框


            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formTestLib"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                ICousreId: 0,
                SCourseCode: '',
                IProblemType: 0,
                STitle: '',
                SContent: '',
                IStuOpen: 0,
                SAnswer: '',
                ITeaCatalog: 0,
                IHardLevel: 0,
                IDiffLevel: 0,
                SPointers: '',
                SKeyWords: '',
                SCharpter: '',


            }),


            //用户列表Grid头部列名称
            headers: [




 { displayText: '标题', value: 'STitle', width: 'auto' },
 { displayText: '对应大纲位置', value: 'ITeaCatalog', width: 'auto' },
 { displayText: '难易度', value: 'IHardLevel', width: 'auto' },



            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/TestLibExt/Search/";
            },

            
            
            dataNodeSelect: function (id) {
                
                return "/api/TestLibExt/GetPreviewData?id=" + id;
            },


			 initEd: function () {
			    //gird初始化的后置事件 信息

			},



        };

        gdViewModel = new gridViewModel(options);

        
        //转换函数，把题型数字转换成对应的字符串   
        gdViewModel.ChangeProblemType = function (IProblemType) {
            switch (IProblemType) {
                case 1:
                    return "单项选择题";
                    break;
                case 2:
                    return "多项选择题";
                    break;
                case 3:
                    return "判断题";
                    break;
                default:
                    break;
            }
        }
        
        //点击“确认修改”执行的操作
        self.ConfirmToChange = function ()
        {
            
            var tempId = $('input:radio[name="userSelector"]:checked').val();//获取被选中的试题Id;
            var tempPaperDetailId = $("#HiddenPaperDetailId").val();//取得当前将被替换的试题的Paperdetail的id；HiddenIStrategyID
            var tempIStrategyID = $("#HiddenIStrategyID").val();
            $.ajax({
                url: "/TestLibPaperExt/ChangeQuestion/",
                type: "POST",
                data: { paperdetailid: tempPaperDetailId, libid: tempId, StrategyID: tempIStrategyID },
                success: function ()
                {
                   
                    window.location.href = "/TeacherManger/TestPaperPreview?PaperID=" + $("#HiddenPaperID").val();
                    
                }
            })
                


        }

        //点击“取消修改”，返回试卷预览页面
        self.BackToPreview = function () {
            
            window.location.href = "/TeacherManger/TestPaperPreview?PaperID=" + $("#HiddenPaperID").val();
        }

        //9/1;所在节的处理
        gdViewModel.chaptesr = ko.observableArray();

        //在被选章里面绑定节
        gdViewModel.arrayBindSesson = ko.observableArray();
        gdViewModel.selectedchapter = ko.observableArray();//当前被选中的章
        gdViewModel.myChange = function (a, b, c, d) {//改变所选章时移动

            gdViewModel.arrayBindSesson.removeAll();//移除绑定的节

            var selV = $("#txtbSrSCharpter").find("option:selected").attr("data-value");
            if (selV == null || selV == "")
                return;
            $.getJSON("/api/TestLibExt/GetSession?ID=" + selV, null, function (data) {
                $.each(data, function (m, n) {

                    gdViewModel.arrayBindSesson.push(n);

                });

            });
        };

        
        gdViewModel.init();
        ko.applyBindings(gdViewModel);

        


    });

</script>


<!--/end grid code-->

